<?php

namespace app\common\model;

use think\Model;

/**
 * 租赁模型
 */
class Lease extends Model
{
  protected $table = 'pre_lease';

  protected $autoWriteTimestamp = true;

  protected $createTime = 'createtime';

  protected $updateTime = false;


  protected $append = [
    'status_text', // 订单状态
    'express_text', // 快递公司名称
    'card_text', //证件照片
  ];

  public function getStatusTextAttr($value, $data)
  {
    $status = (empty($data['status']) && !is_numeric($data['status']) == true) ? null :  $data['status'];

    switch ($status) {
      case '1':
        return '已下单';
      case '2':
        return '已发货';
      case '3':
        return '已收货';
      case '4':
        return '已归还';
      case '5':
        return '未评价';
      case '6':
        return '已完成';
    }
  }

  public function getExpressTextAttr($value, $data)
  {
    $expid = empty($data['expid'])  ? null :  $data['expid'];
    $name = Expressquery::where('id', $expid)->value('name');

    return $name;
  }

  public function getCardTextAttr($value, $data)
  {
    $url = config('site.url');
    $card = !empty($data['card']) ? $url . $data['card'] : '';

    return $card;
  }

  public function product()
  {
    return $this->belongsTo('app\common\model\Product\Product', 'proid', 'id', [], 'LEFT')->setEagerlyType(0);
  }

  public function business()
  {
    return $this->belongsTo('app\common\model\Business\Business', 'busid', 'id', [], 'LEFT')->setEagerlyType(0);
  }
}
